//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.product.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.live.configuration.SessionInfo;
import com.ruoyi.live.base.domain.LiveProduct;
import com.ruoyi.live.base.mapper.LiveProductMapper;
import com.ruoyi.live.tool.commons.ICommons;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LiveProductService {
    private static final Logger log = LoggerFactory.getLogger(LiveProductService.class);
    @Autowired
    LiveProductMapper dao;

    public LiveProductService() {
    }

    public void addLiveProduct(LiveProduct entity) throws Exception {
        try {
            entity.setCreateTime(System.currentTimeMillis());
            entity.setCreateUser(SessionInfo.getUserId());
            entity.setState(1);
            this.dao.insert(entity);
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("新增LiveProduct失败,编号LiveProductService-addLiveProduct-1");
            throw new Exception("新增失败,编号LiveProductService-addLiveProduct-1");
        }
    }

    public void updateLiveProduct(LiveProduct entity) throws Exception {
        try {
            this.dao.updateById(entity);
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("更新LiveProduct失败,编号LiveProductService-updateLiveProduct-1,id:{}", entity.getId());
            throw new Exception("更新失败,编号LiveProductService-updateLiveProduct-1");
        }
    }

    public LiveProduct getLiveProduct(Long id) {
        return (LiveProduct)this.dao.selectById(id);
    }

    public int deleteLiveProduct(Long[] ids) {
        UpdateWrapper<LiveProduct> updateWrapper = new UpdateWrapper<LiveProduct>();
        updateWrapper.in("id", ids).set("state", 0);
        int count = this.dao.update(new LiveProduct(), updateWrapper);
        return count;
    }

    public List<LiveProduct> query(LiveProduct entity) {
        QueryWrapper<LiveProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(!ICommons.isNullOrEmpty(entity.getId()), "id", entity.getId())
                .eq(!ICommons.isNullOrEmpty(entity.getState()), "state", entity.getState())
                .eq(!ICommons.isNullOrEmpty(entity.getCreateTime()), "create_time", entity.getCreateTime())
                .eq(!ICommons.isNullOrEmpty(entity.getCreateUser()), "create_user", entity.getCreateUser())
                .like(!ICommons.isNullOrEmpty(entity.getProductName()), "product_name", entity.getProductName())
                .eq(!ICommons.isNullOrEmpty(entity.getProductType()), "product_type", entity.getProductType());

        return this.dao.selectList(queryWrapper);
    }

    public List<LiveProduct> queryList() {
        return this.dao.selectList(new QueryWrapper());
    }
}
